#-----------------------------------------------------------------------------
# Project:     Multi-Programmer Game Demo
# Name:        Paddle.py
# Purpose:     Controllable Paddle Object
# 
# Authors:     Chris Spooner, Chris La-Roo
# Main Author: Chris Spooner
#
# Created:     11/30/2012
# Copyright:   (c) Chris Spooner 2012
# Licence:     New BSD
#-----------------------------------------------------------------------------
import pygame, math, sys, random
#stuff 
class Paddle():
    def __init__(self, maxSpeed, position, screenSize):
        self.surface = pygame.image.load("rsc/paddle/paddle.png")
        self.surface = pygame.transform.scale(self.surface,
                                              (100, 30))
        self.rect = self.surface.get_rect()
        self.speed = [0,0]
        self.maxSpeed = maxSpeed
        self.place(position)
        self.screenWidth = screenSize[0]
        self.screenHeight = screenSize[1]
        self.radius = self.rect.width/2
        
    def  __str__(self):
        return "I'm a paddle" + str(self.rect.center)
     
    def place(self, position):
        self.rect.center = position
        print "I've moved to", position
        
    def move(self):
        self.rect = self.rect.move(self.speed)
        print "I've moved", self.speed
    
    def collideWall(self, screenWidth, screenHeight):
        if (self.rect.left < 0 
            or self.rect.right > self.screenWidth):
            self.speed[0] = 0
        if (self.rect.top < 0 
            or self.rect.bottom >self.screenHeight):
            self.speed[1] = 0
        print "trying to hit edges of screen", screenWidth, screenHeight
    
    def direction(self, dir):
        if dir == "up":
            self.speed[1] = -self.maxSpeed
        elif dir == "down":
            self.speed[1] = self.maxSpeed
        elif dir == "right":
            self.speed[0] = self.maxSpeed
        elif dir == "left":
            self.speed[0] = -self.maxSpeed
        
        elif dir == "stop up":
            self.speed[1] = 0
        elif dir == "stop down":
            self.speed[1] = 0
        elif dir == "stop right":
            self.speed[0] = 0
        elif dir == "stop left":
            self.speed[0] = 0
        print "moving in direction", dir
        
    def distToPoint(self, pt):
        x1 = self.rect.center[0]
        x2 = pt[0]
        y1 = self.rect.center[1]
        y2 = pt[1]
        return math.sqrt(((x2-x1)**2)+((y2-y1)**2))
        
            
    def ballCollide(self, other):
        if (self.rect.right > other.rect.left 
            and self.rect.left < other.rect.right):
            if (self.rect.bottom > other.rect.top and 
                self.rect.top < other.rect.bottom):
                if (self.distToPoint(other.rect.center)
                    < self.radius + other.radius):  
                    self.speed[0] = self.speed[0] * -1
                    self.speed[1] = self.speed[1] * -1
                    other.speed[0] = other.speed[0] * -1
                    other.speed[1] = other.speed[1] * -1